package com.application.Controller;


import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.application.Activity.R;
import com.application.Activity.frmBieuQuyetMoiRoiNhom;
import com.application.Activity.frmChatPeerActivity;

public class NotificationController{
	private static final int NOTIFY_1 = 0x1001;
	private static final int NOTIFY[] = {0x1001,0x1002, 0x1003, 0x1004, 0x1005, 0x1006, 0x1007, 0x1008, 0x1009, 0x1010};
	private static int _count=0;
	public static void sendNotification(Context caller, Class<?> activityToLaunch, String title, String msg, int mood) {
		NotificationManager notifier = (NotificationManager) caller.getSystemService(Context.NOTIFICATION_SERVICE);

		// Create this outside the button so we can increment the number drawn over the notification icon.
		// This indicates the number of alerts for this event.
		final Notification notify = new Notification(R.drawable.stat_happy, "", System.currentTimeMillis());

		notify.icon = R.drawable.stat_happy;
		notify.tickerText = "Có tin nhắn từ hệ thống MES!";
		notify.when = System.currentTimeMillis();
		notify.flags |= Notification.FLAG_AUTO_CANCEL;
		notify.defaults = mood;

		Intent toLaunch = new Intent(caller, activityToLaunch);
		PendingIntent intentBack = PendingIntent.getActivity(caller, 0, toLaunch, 0);

		notify.setLatestEventInfo(caller, title, msg, intentBack);
		if(_count == 10)
			_count = 0;
		notifier.notify(NOTIFY[_count], notify);
		_count++;
		
	}

	public static void sendNotification(Context caller, Class<?> activityToLaunch, String title, String msg, int mood,String username,String ipfriend) {
		NotificationManager notifier = (NotificationManager) caller.getSystemService(Context.NOTIFICATION_SERVICE);

		// Create this outside the button so we can increment the number drawn over the notification icon.
		// This indicates the number of alerts for this event.
		final Notification notify = new Notification(R.drawable.ic_up, "", System.currentTimeMillis());

		notify.icon = R.drawable.new_mess;
		notify.tickerText = "Bạn có tin nhắn trò chuyện mới!";
		notify.when = System.currentTimeMillis();
		notify.flags |= Notification.FLAG_AUTO_CANCEL;
		notify.defaults = mood;

		Intent toLaunch = new Intent(caller, activityToLaunch);
		//toLaunch.putExtra(frmChatPeerActivity.IP_CHAT_PEER, ipfriend);
		//toLaunch.putExtra(frmChatPeerActivity.USERNAME, username);
		frmChatPeerActivity.IPMyFriend=ipfriend;
		frmChatPeerActivity.UserNameMyFriend=username;
		//setResult(frmChatPeerActivity.CODE_CHATPEER, toLaunch);
		
		PendingIntent intentBack = PendingIntent.getActivity(caller, 0, toLaunch, 0);

		notify.setLatestEventInfo(caller, title, msg, intentBack);
		if(_count == 10)
			_count = 0;
		notifier.notify(NOTIFY[_count], notify);
		_count++;
	}

	public static void sendNotification(Context caller, Class<?> activityToLaunch, String title, String msg, int mood,String username) {
		NotificationManager notifier = (NotificationManager) caller.getSystemService(Context.NOTIFICATION_SERVICE);

		// Create this outside the button so we can increment the number drawn over the notification icon.
		// This indicates the number of alerts for this event.
		final Notification notify = new Notification(R.drawable.ic_up, "", System.currentTimeMillis());

		notify.icon = R.drawable.new_mess;
		notify.tickerText = "Bạn có tin nhắn trò chuyện mới!";
		notify.when = System.currentTimeMillis();
		notify.flags |= Notification.FLAG_AUTO_CANCEL;
		notify.defaults = mood;

		Intent toLaunch = new Intent(caller, activityToLaunch);
		
		Bundle ex = new Bundle();
		ex.putInt("ID", 2); 		
		toLaunch.putExtras(ex);
		//toLaunch.putExtra(frmChatPeerActivity.IP_CHAT_PEER, ipfriend);
		//toLaunch.putExtra(frmChatPeerActivity.USERNAME, username);
		//frmChatPeerActivity.IPMyFriend=ipfriend;
		
		frmChatPeerActivity.UserNameMyFriend=username;
		//setResult(frmChatPeerActivity.CODE_CHATPEER, toLaunch);
		
		PendingIntent intentBack = PendingIntent.getActivity(caller, 0, toLaunch, 0);

		notify.setLatestEventInfo(caller, title, msg, intentBack);
		if(_count == 10)
			_count = 0;
		notifier.notify(NOTIFY[_count], notify);
		_count++;
	}
	
//	public static void clear(Activity caller) {
//		NotificationManager notifier = (NotificationManager) caller.getSystemService(Context.NOTIFICATION_SERVICE);
//		notifier.cancelAll();
//	}


}
